package com.example.selfcontrol.controller;

import com.example.selfcontrol.config.Response;
import com.example.selfcontrol.dto.MessageDTO;
import com.example.selfcontrol.dto.MessageTotalDTO;
import com.example.selfcontrol.entity.Message;
import com.example.selfcontrol.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/message")
@Api(value = "消息通知表")
public class MessageController {
    @Autowired
    private MessageService messageService ;

    @PostMapping("/add")
    @ApiOperation("A发送消息给B")
    public Response addMessage(MessageDTO messageDTO) {
        return messageService.addMessage(messageDTO) ;
    }

    @GetMapping("/get")
    @ApiOperation("查找A给B发送的信息")
    public List<Message> getMessage(Long userId, Long notifyId) {
        return messageService.getMessage(userId,notifyId) ;
    }

    @GetMapping("/count/unread")
    @ApiOperation("查找未读消息数")
    public int getUnReadMessage(Long userId, Long notifyId) {
        return messageService.getUnReadMessage(userId,notifyId) ;
    }

    @PutMapping("/read")
    @ApiOperation("使消息变成已读")
    public Response ChangeReadStatus(Long userId, Long notifyId,@RequestParam List<String> readedList) {
        System.out.println(readedList);
        return messageService.ChangeReadStatus(userId,notifyId,readedList) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation("物理删除消息")
    public Response DeleteMessage(Long userId, Long notifyId, @RequestParam List<String> readedList) {
        return  messageService.DeleteMessage(userId,notifyId,readedList) ;
    }
}
